package com.project.sianet.data;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.project.sianet.R;
import com.project.sianet.entidades.Actividad;
import com.project.sianet.util.TypefaceManager;

public class ActividadArrayAdapter extends ArrayAdapter<Actividad> {

	private static final String tag = "ActividadArrayAdapter";
    private TextView titulo;
    private TextView icono;
    private List<Actividad> actividades = new ArrayList<Actividad>();
    
    public ActividadArrayAdapter(Context context, int textViewResourceId,
            List<Actividad> objects) {
        super(context, textViewResourceId, objects);
        this.actividades = objects;

    }
    
    public int getCount() {
    	return this.actividades.size();
    }
 
    public Actividad getItem(int index) {
        return this.actividades.get(index);
    }
    
	public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        if (row == null) {
            // ROW INFLATION
            Log.d(tag, "Starting XML Row Inflation ... ");
            LayoutInflater inflater = (LayoutInflater) this.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.actividad_list, parent, false);
            Log.d(tag, "Successfully completed XML Row Inflation!");
        }
 
        Actividad a = getItem(position);

        titulo = (TextView) row.findViewById(R.id.act_titulo);
        icono = (TextView) row.findViewById(R.id.act_ico);

        titulo.setText(a.actTitulo);
        titulo.setTypeface(TypefaceManager.getInstance().getTypeface("MavenPro"), Typeface.NORMAL);
        
        switch(a.actTipo) {
        
        	case Agenda:
        		icono.setText("a");
        		icono.setBackgroundResource(R.drawable.tv_agenda);
        		break;
        	case Descarga:
        		icono.setText("d");
        		icono.setBackgroundResource(R.drawable.tv_descarga);
        		break;
        	case Enlaces:
        		icono.setText("w");
        		icono.setBackgroundResource(R.drawable.tv_enlace);
        		break;
        	case Evento:
        		icono.setText("v");
        		icono.setBackgroundResource(R.drawable.tv_evento);
        		break;
        	case Noticia:
        		icono.setText("n");
        		icono.setBackgroundResource(R.drawable.tv_noticia);
        		break;
        	case Tareas:
        		icono.setText("t");
        		icono.setBackgroundResource(R.drawable.tv_tarea);
        		break;
        	case Examen:
        		icono.setText("e");
        		icono.setBackgroundResource(R.drawable.tv_examen);
        		break;
        	case Cuaderno:
        		icono.setText("c");
        		icono.setBackgroundResource(R.drawable.tv_cuaderno);
        		break;
        	default:
        		break;
        
        }
        icono.setTypeface(TypefaceManager.getInstance().getTypeface("MavenPro"), Typeface.BOLD);

        return row;
    }
	
}
